Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add NoRedundantInlineAnnotationsRule #12

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Slamdunk
Copy link
Owner

No description provided.

@Slamdunk Slamdunk changed the title [WIP] Add NoUselessInlineAnnotationsRule [WIP] Add NoRedundantInlineAnnotationsRule Jul 10, 2019
$foo1 = $this->bar1();

/** @var Bar $foo2 */
$foo2 = $this->bar2();
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ondrejmirtes after using more and more @phpstan I now trust it much more than developers annotations: now I'm scared that in the future this kind of redundant annotation (::bar2 already returns Bar) will hide bugs if the related API change.

Is such a rule, NoRedundantInlineAnnotationsRule, feasable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, first of all, make sure to run PHPStan with conf/bleedingEdge.neon (include it in phpstan.neon), it contains some additional rules around @var.

But the main problem is that you need to consider these things:

  1. @var is sometimes used for more precise casting - I get object and I know it's Foo.
  2. @var is sometimes used for fixing wrong 3rd party phpDoc - I get string and I know it's int. This point makes any type verification impossible.
  3. Sometimes @var is used because PHPStan understands the type, but IDE doesn't.

These points make any general rule impossible. But some more proprietary variant is possible to implement, very easily. I'd recommend you to look how those bleeding edge rules are implemented in 0.11.9 (https://github.com/phpstan/phpstan/releases/tag/0.11.9) - commits are linked in the release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants